package org.room402.utile.chat;

import cn.hutool.json.JSONUtil;
import org.room402.constant.chat.MessageAction;
import org.room402.entity.chat.MessageEvent;
import org.room402.entity.chat.UserSession;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.web.reactive.socket.WebSocketMessage;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Mono;

import java.nio.charset.StandardCharsets;

public class FastChatUtil {

    /**
     * 驳回消息
     */
    public static Mono<Void> reject(UserSession userSession, String message) {
        MessageEvent messageEvent = MessageEvent.form(null, userSession.getId(), MessageAction.reject, message);
        WebSocketSession session = userSession.getSession();
        return session.send(Mono.just(session.textMessage(JSONUtil.toJsonStr(messageEvent))));
    }
}
